﻿function createXmlHttp() { 
	if (typeof XMLHttpRequest != "undefined") {
		return new XMLHttpRequest();
	} else if (typeof ActiveXObject != "undefined") {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		throw new Error("AJAX not supported");
	}
}

var xmlHttp = createXmlHttp();

function showAnswer() {
	if (xmlHttp.readyState==4) {
		var n =	document.getElementById("hkd").value;
		var e =	document.getElementById("usd");
		e.innerHTML = n + 'HKD = ' + xmlHttp.responseText + ' USD';
	}	
}

function callServer(n) {
	if(xmlHttp==null) {
		alert("NO AJAX!");
		return;
	}
	var url="hkd2usd.cgi";
	url = url + "?hkd=" +n;
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = showAnswer;
	xmlHttp.send(null);
}

window.onload = function() {
	 document.getElementById("hkd").onkeyup = callServer(this.value);
};

